package com.eascs.cfsapi.controller;

import com.eascs.admin.common.controller.BaseMasterViewController;
import com.eascs.app.dao.PageResult;
import com.eascs.cfsapi.service.CfsApiLoanapplyService;
import com.eascs.cfsapi.vo.LoanapplyPageVo;
import com.eascs.common.util.StringUtil;
import com.eascs.common.util.UrlUtil;
import com.eascs.site.page.PaginationInfo;
import com.eascs.site.view.ViewContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * 流通金服--查询申请贷款单信息
 */
@Controller
@RequestMapping("/cfs")
public class CfsLoanapplyController extends BaseMasterViewController {

    @Autowired
    private CfsApiLoanapplyService cfsApiLoanapplyService;

    @RequestMapping("/index")
    public  String queryLoanapplyPage(LoanapplyPageVo loanapplyPageVo){
        String o2ourl = "/cfs/index";
        String name = StringUtil.isBlank(loanapplyPageVo.getName()) ? "" : loanapplyPageVo.getName();
        String province = StringUtil.isBlank(loanapplyPageVo.getProvince()) ? "" : loanapplyPageVo.getProvince();
        String city = StringUtil.isBlank( loanapplyPageVo.getCity())? "" : loanapplyPageVo.getCity() ;
        String startTime = StringUtil.isBlank(loanapplyPageVo.getStartTime()) ? "" :loanapplyPageVo.getStartTime();
        String endTime = StringUtil.isBlank(loanapplyPageVo.getEndTime()) ? "" :loanapplyPageVo.getEndTime();
        o2ourl = UrlUtil.appendUrl(o2ourl, "name", name);
        o2ourl = UrlUtil.appendUrl(o2ourl, "province", province);
        o2ourl = UrlUtil.appendUrl(o2ourl, "city", city);
        o2ourl = UrlUtil.appendUrl(o2ourl, "startTime", startTime);
        o2ourl = UrlUtil.appendUrl(o2ourl, "endTime", endTime);
        o2ourl = o2ourl + "&pageIndex=";
        PageResult<Object[]> loanapplyPage = cfsApiLoanapplyService.queryLoanapplyPage(loanapplyPageVo);
        String titles[] = { "申请时间","姓名", "电话","申请金额（元）","申请期限","省区","城市","县/区","详细地址" };
        PaginationInfo o2oPagingInfo = new PaginationInfo(loanapplyPage, titles, o2ourl);
        o2oPagingInfo.setBuildPagingNavigation(true);
        o2oPagingInfo.setBuildRowNumber(true);
        o2oPagingInfo.setFirstRenderColumnIndex(0);
        ViewContext.put("o2oPagingInfo", o2oPagingInfo);
        ViewContext.put("vo", loanapplyPageVo);
        return "/cfsapi/index";
    }

}
